package com.sc.controller.Vast_controller;

import com.sc.Vast_pojo.dto.PublicDeviceDTO;
import com.sc.Vast_pojo.dto.PublicDevicePageQueryDTO;
import com.sc.Vast_pojo.vo.PublicDeviceVO;
import com.sc.result.PageResult;
import com.sc.result.Result;
import com.sc.service.Vast_service.PublicDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Vast
 * @version 1.0
 * @function:公共设备管理控制器
 */
@Slf4j
@Api(tags = "公共设备管理相关接口")
@RestController
@RequestMapping("/publicDevice")
@CrossOrigin
public class PublicDeviceController {
    @Autowired
    private PublicDeviceService publicDeviceService;

    /**
     * 公共设备管理分页查询
     * @param deviceFixDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("公共设备管理分页查询")
    public Result<PageResult> pageQuery(PublicDevicePageQueryDTO publicDevicePageQueryDTO){
        log.info("公共设备管理分页查询,{}",publicDevicePageQueryDTO);
        PageResult pageResult=publicDeviceService.pageQuery(publicDevicePageQueryDTO);
        return Result.success(pageResult);
    }
    /**
     * 新增公共设备
     * @param publicDeviceDTO
     * @return
     */
    @PostMapping("/saveDevice")
    @ApiOperation("新增公共设备")
    public Result save(@RequestBody PublicDeviceDTO publicDeviceDTO){
        log.info("新增公共设备，{}",publicDeviceDTO);
        publicDeviceService.save(publicDeviceDTO);
        return Result.success(null,"新增成功");
    }

    /**
     * 根据主键id更新公共设备信息
     * @param publicDeviceDTO
     * @param id
     * @return
     */
    @PostMapping("/updataPublicDevice")
    @ApiOperation("更新公共设备信息")
    public Result update(@RequestBody PublicDeviceDTO publicDeviceDTO){
        log.info("更新公共设备信息，{}",publicDeviceDTO,publicDeviceDTO.getId());
        publicDeviceService.update(publicDeviceDTO,publicDeviceDTO.getId());
        return Result.success(null,"更新成功");
    }

    @DeleteMapping("/{id}")
    public Result deleteDeviceById(@PathVariable("id") Integer id)
    {
        log.info("删除设备:{}",id);
        publicDeviceService.removeById(id);
        return Result.success();
    }

    /**
     * 查询设备详情,并且显示出对应的维修记录
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("查询设备详情")
    public Result<PublicDeviceVO> getById(@PathVariable("id") Integer id){
        PublicDeviceVO publicDeviceVO=publicDeviceService.getById(id);
        return Result.success(publicDeviceVO);
    }

    /**
     * 公共设备删除
     * @param ids
     * @return
     */
    @DeleteMapping("/deleteByIds")
    @ApiOperation("公共设备删除")
    public Result deleteByIds(@RequestBody List<Integer> ids){
        log.info("公共设备删除,{}",ids);
        publicDeviceService.removeByIds(ids);
        return Result.success();
    }
}
